<template>
  <div>
    <div id="change_container">
      <p>修改密码</p>

      <div class="change_container_form">
        <div class="change_form_name">
          <span>原密码</span>
          <el-input
            @blur="blurped"
            v-model="oldpwd"
            style="width: 250px"
          ></el-input>
        </div>
        <div class="change_form_pwd">
          <span>新密码</span>
          <el-input v-model="newpwd" style="width: 250px"></el-input>
        </div>
        <div class="change_form_pwd">
          <span>确认新密码</span>
          <el-input v-model="affusername" style="width: 250px"></el-input>
        </div>

        <div class="change_btn">
          <el-button @click="affbtn" type="primary">确定</el-button>
          <el-button>重置</el-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { oldpwd, newpwd } from "@/apis/users";
export default {
  data() {
    return {
      oldpwd: "",
      newpwd: "",
      affusername: "",
    };
  },

  methods: {
    blurped() {
      // console.log(oldpassid);
      oldpwd({ id: localStorage.id, oldPwd: this.oldpwd }).then((res) => {
        console.log(res);
        if (!res.data.code == 0) {
          this.$message.error("旧密码错误,请重新输入");
        }
      });
      // console.log(this.userpwd, oldpassid);
    },

    affbtn() {
      if (this.newpwd == this.affusername) {
        newpwd({ id: localStorage.id, newPwd: this.affusername }).then(
          (res) => {
            console.log(res);
            if (res.data.code == 0) {
              this.$message({
                message: "密码修改成功,请重新登陆",
                type: "success",
              });

              this.$router.push("/");
            }
          }
        );
      }
    },
  },
};
</script>

<style lang="less" scoped>
#change_container {
  background-color: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  p {
    line-height: 50px;
    border-bottom: 1px solid #f4f5f9;
    padding: 0 20px;
    color: #848485;
    margin-bottom: 20px;
  }
  .change_container_form {
    width: 350px;
    margin-left: 30px;
    .change_form_name,
    .change_form_pwd {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      span {
        flex: 1;
        text-align: right;
        margin-right: 10px;
      }
    }
    .change_btn {
      display: flex;
      justify-content: center;
      padding-bottom: 20px;
    }
  }
}
</style>